package com.demo.rocketmq.producer;

import com.demo.rocketmq.consumer.BlockConsumer;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.Date;
import java.util.concurrent.TimeUnit;

/**
 * 测试消息堆积问题
 */
@SpringBootTest
public class BlockProducer {

    @Resource(name = "rocketMQTemplate")
    private RocketMQTemplate rocketMqTemplate;

    @Test
    public void send() throws InterruptedException {
        for (int i = 0; i < 10000000; i++) {
            String message = i + " - " + "Hello, World! 日期：" + new Date();
            rocketMqTemplate.convertAndSend(BlockConsumer.BLOCK_TOPIC, message);
        }
        TimeUnit.MINUTES.sleep(20);
    }
}
